package net.xiduth.game.player.content;

import net.xiduth.game.item.Item;
import net.xiduth.game.player.Player;
import net.xiduth.utils.Utils;

/**
 * 
 * @author Kova+ (Alex)
 *
 */
public class ItemGambler {
	
	public static void gambleItem(Player player, int slotId) {
		Item gambledItem = player.getInventory().getItem(slotId);
		if (gambledItem == null)
			return;
		int wealth = Shop.getBuyPrice(gambledItem);
		if (player.getInventory().containsItem(gambledItem.getId(), 1)) {
			player.getInventory().deleteItem(gambledItem.getId(), 1);
			int random = Utils.getRandom(5000);
			//player.sendMessage(String.valueOf(random));
			if (random >= 4800 || random <= 200) {
				if (player.getInventory().getFreeSlots() < 2) {
					player.sendMessage("You don't have enough room within your inventory to recieve your prize, it's gone to your bank!");
					player.getBank().addItem(gambledItem.getId(), 2, true);
					return;
				} else {
					player.getInventory().addItem(gambledItem.getId(), 2);
					player.sendMessage("<col=ffoooo>You won the item gambler and doubled your item!");
					player.getDialogueManager().startDialogue("SimpleMessage", "You won the item gambler and doubled your item!");
					return;
				}
			} else if (random >= 2300 && random <= 2350) {
				if (wealth >= 100000000) {
					giveDonator(player);
					player.sendMessage("You've received your item back as well as a donator status!");
					if (player.getInventory().getFreeSlots() < 2) {
						player.sendMessage("You don't have enough room within your inventory to recieve your prize, it's gone to your bank!");
						player.getBank().addItem(gambledItem.getId(), 1, true);
						return;
					} else {
						player.getInventory().addItem(gambledItem.getId(), 1);
						player.getDialogueManager().startDialogue("SimpleMessage", "You won the item gambler and doubled your item!");
						return;
					}
				} else {
					player.sendMessage("The price of that item doesn't allow you to win donator status.");
					return;
				}
			} else {
				player.sendMessage("<col=ffoooo>Hard luck! You won nothing this time.");
				return;
			}
		}
	}
	
	public static void sendInvoData(Player player) {
		player.getAttributes().put("item_gamble", true);
		player.getPackets().sendItems(93, player.getInventory().getItems());
		player.getInterfaceManager().sendInventoryInterface(1266);
		player.getPackets().sendUnlockIComponentOptionSlots(1266, 0, 0, 27, 0, 1, 2);
		player.getPackets().sendInterSetItemsOptionsScript(1266, 0, 93, 4, 7, "Gamble");
	}
	
	private static void giveDonator(Player player) {
		if (player.isDonator() == false) {
			player.setDonator(true);
			return;
		} else if (player.isDonator() == true) {
			player.setSuperDonator(true);
			return;
		} else if (player.isSuperDonator() == true) {
			player.setExtremeDonator(true);
			return;
		} else if (player.isExtremeDonator() == true) {
			player.setVIPDonator(true);
			return;
		}
		return;
	}
}
